<?php
/**
 * Created by a front-end programmer.
 * Author: lauwen
 * Mail:lauwencn@gmail.com
 */
class IndexController extends CommonController {
    public function index(){
        $data = $this->getUserMenu($_SESSION['uid'], 1);
        $parent_ids = array_unique(array_column($data, 'parent_id'));
        $parentMenu = array();
        foreach ($parent_ids as $v){
            $res = K("Access")->get_one_ca($v);
            array_push($parentMenu, $res);
        }
        $this->assign('childMenu', $data);
        $this->assign('parentMenu', $parentMenu);
        $this->display();
    }
    public function getUserMenu($uid, $level){
        $ur = K("UserRole")->get_all_cu($uid);
        $access = array();
        foreach ($ur as $v){
            $ra = K("RoleAccess")->get_all_cr($v['rid']);
            $rid = array_column($ra, 'aid');
            $access = array_unique(array_merge($access, $rid));
        }
        $result = array();
        foreach ($access as $v){
            $info = K("Access")->get_one_cal($v, $level);
            if($info){
                array_push($result, $info);
            }
        }
        return $result;
    }
}
?>